package org.example.ai.controller;

import lombok.RequiredArgsConstructor;
import org.example.ai.repository.ChatHistoryRepository;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class CustomerServiceController {
    private final ChatHistoryRepository chatHistoryRepository;
    private final ChatClient servicechatClient;
    @RequestMapping(value = "/service",produces = "text/html;charset=utf-8")//produces设置响应结果类型
    public Flux<String> chatservice(String prompt,String chatId){
        //保存会话Id
        chatHistoryRepository.save("service",chatId);
        //请求模型
        return servicechatClient.prompt()
                .user(prompt)
                .advisors(a->a.param((ChatMemory.CONVERSATION_ID),chatId))
                .stream()
                .content();
    }
}
